<template>
  <div>
    <el-row>
      <!-- 置顶tag -->
      <el-button size="small" type="warning" @click="toup(uid)">置顶</el-button>
      <!-- 编辑tag按钮 -->
      <el-button size="small" type="primary" @click="toedit(uid)"
        >编辑</el-button
      >
      <!-- 删除tag按钮 -->
      <el-button size="small" type="danger" @click="todel(uid)">删除</el-button>
    </el-row>
  </div>
</template>

<script>
import {
  blogSortstick,
  tagSortstick,
  blogSortdel,
  blogTagdel,
} from "@/api/blog.js";
export default {
  name: "caozuobox",
  props: {
    uid: {
      required: true,
    },
    type: {
      required: true,
    },
  },
  methods: {
    async toup(id) {
      const res =
        this.type === "sort"
          ? await blogSortstick({ uid: this.uid })
          : await tagSortstick({ uid: this.uid });
      this.$emit("changelist");
    },
    toedit(id) {
      console.log(id);
      console.log(this.type);
    },
    async todel(id) {
      try {
        const { data: res } =
          this.type === "sort"
            ? await blogSortdel([{ uid: this.uid }])
            : await blogTagdel([{ uid: this.uid }]);
        if (res.code === "error") {
          this.$message.warning(res.data);
          return false;
        }
        this.$message.success(res.data);
        this.$emit("changelist");
      } catch (error) {
        console.log("error", error);
      }
    },
  },
};
</script>

<style lang="less" scoped></style>
